﻿using ERPWinFormWork.Sales.DTO;
using ERPWinFormWork.Sales.ErrorCode;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERPWinFormWork.Sales
{
    public partial class QuotationDetailsForm : Form
    {
        private ApiClient _apiClient;
        public QuotationDetailsForm(int Id)
        {
            InitializeComponent();
            _apiClient = new ApiClient(AppConfig.ApiBaseUrl);
            GetInfo(Id);
        }

        private void btnQuotationFan_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK; // 设置对话框结果，方便上一级判断
            this.Close();
        }


        private async void GetInfo(int Id)
        {

            var parameters = new Dictionary<string, string>
            {
                   { "Id", Id.ToString()},  
            };
            var response = await _apiClient.GetAsync<ApiResponse<QuotationParticularsDTO>>(
                    endpoint: "Sales/QuotationParticulars",
                    parameters: parameters
                );
            if (response != null && response.code == 200)
            {
                var quotation = response.data.quotationDTO;
                var quotationParticulars = response.data.quotationParticularsDTOs;

                txtQuotationNumber.Text= quotation.Quotation_Number;
                txtQuotationName.Text= quotation.Quotation_Name;
                txtQuotationTax_Rate.Text = quotation.Tax_Rate.ToString();
                cboCustomer.Text = quotation.Customer_Name;
                txtQuotationDescr.Text=quotation.Quotation_Descr;

                dgvproduct.DataSource= quotationParticulars;

            }
        }
    }
}
